package com.chen10.cattle.ai;

import com.chen10.cattle.ai.inter.GobangAlgorithm;
import com.chen10.cattle.ai.inter.impl.EasyGobangAlgorithm;
import com.chen10.cattle.ai.inter.impl.HardGobangAlgorithm;
import com.chen10.cattle.ai.inter.impl.MediumGobangAlgorithm;
import com.chen10.cattle.ai.model.AiMoveRequest;
import com.chen10.cattle.ai.model.Position;
import com.chen10.cattle.common.enums.response.ErrorEnum;

import java.util.Map;
import java.util.Optional;

public class GobangAIChooser {

    private static final Map<Integer, GobangAlgorithm> algorithms = Map.of(
            0, new EasyGobangAlgorithm(),
            1, new MediumGobangAlgorithm(),
            2, new HardGobangAlgorithm()
    );

    // 根据难度选择不同算法计算最佳移动位置
    public static Position calculateMove(AiMoveRequest aiMoveRequest) {
        return Optional.ofNullable(algorithms.get(aiMoveRequest.getMode()))
                .orElseThrow(() -> new IllegalArgumentException(ErrorEnum.UNKNOWN_AIMODE.getMessage()))
                .calculateMove(aiMoveRequest);
    }
}
